<?php


namespace seecms\lib\builder\query;

trait  Query
{
    /**
     * @var int
     */
    protected $size = 2;

    /**
     * @var array
     */
    protected $data = [];

    /**
     * 表达式
     * @var string
     */
    protected $express = '';

    /**
     * @return int
     */
    public function getSize(): int
    {
        return $this->size ?: 2;
    }

    /**
     * @param int $size
     * @return $this
     */
    public function setSize(int $size)
    {
        if ($size > 4) {
            $size = 4;
        } elseif ($size < 1) {
            $size = 1;
        }

        $this->size = $size;

        return $this;
    }

    /**
     * @return array
     */
    public function getData(): array
    {
        return $this->data;
    }

    /**
     * @param string $field
     * @param string $value
     * @return void
     */
    public function setData(string $field, string $value = '')
    {
        $this->data[$field] = $value;
    }

    /**
     * @return string
     */
    public function getExpress(): string
    {
        return $this->express ?: '=';
    }

    public function setExpress(string $express)
    {
        $this->express = $express;

        return $this;
    }

    public function setExpressIn()
    {
        $this->express = 'in';

        return $this;
    }

    public function setExpressLike()
    {
        $this->express = 'like';

        return $this;
    }
}